//
//  OddNumberDetailsViewController.m
//  KD
//
//  Created by Hubery on 15/8/18.
//  Copyright (c) 2015年 centling. All rights reserved.
//

#import "OddNumberDetailsViewController.h"
#import "BaseCellModel.h"
#import "DetailsTableViewCell.h"
#import "TransactTableViewCell.h"

@interface OddNumberDetailsViewController ()
@property(nonatomic,strong) NSMutableArray *array;
@end

@implementation OddNumberDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UINib *nib = [UINib nibWithNibName:@"TransactTableViewCell" bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:@"TransactCell"];
}

//无论通过哪个方法创建 都是分组样式
-(id)init
{
    return [super initWithStyle:UITableViewStyleGrouped];
}
-(id)initWithStyle:(UITableViewStyle)style
{
    return [super initWithStyle:UITableViewStyleGrouped];
}


#pragma mark - UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
     return self.oddNumberGroup.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSMutableArray *array = self.oddNumberGroup[section];
   return array.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        TransactTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"TransactCell" forIndexPath:indexPath];
        cell.oddNumberModel = self.oddNumber;
        return cell;
    }else{

        DetailsTableViewCell *cell = [DetailsTableViewCell cellWithTableView:tableView];
        NSMutableArray *array  = self.oddNumberGroup[indexPath.section];
        BaseCellModel *item = array[indexPath.row];
        cell.item = item;
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];//点击后取消选中
    
//    SettingGroup *g  = self.datas[indexPath.section];
//    SettingItem *item = g.items[indexPath.row];
//    /**
//     如果是尖尖类 才需要跳转
//     */
//    if (item.option != nil) {
//        item.option();
//    }else if ([item isKindOfClass:[SettingArrowItem class]]) {
//        SettingArrowItem *newItem = (SettingArrowItem *)item;
//        UIViewController *vc = [[newItem.destVc alloc]init];
//        vc.title = item.title;
//        [self.navigationController pushViewController:vc animated:YES];
//    }
    
    NSArray *array = self.oddNumberGroup[indexPath.section];
    BaseCellModel *model = array[indexPath.row];
    if (model.option != nil) {
        model.option();
    }
//    }else if ([model isKindOfClass:[DetailsTableViewCell class]])
//    {
//        //跳转
//    }
}


#pragma mark - 懒加载
- (NSMutableArray *)oddNumberGroup
{
        if (_oddNumberGroup == nil) {
            _oddNumberGroup = [NSMutableArray array];
        }
        return _oddNumberGroup;
    
}
@end
